package com.pp.proposalPrint.shared;

import java.util.ArrayList;
import java.util.List;

// Abstract class for describing the list of objects derived from ProposalContent
// Materials class is a subclass of this class for example
public abstract class ProposalContentList<C extends ProposalContent> {

	// The list of objects
	protected final List<C> CONTENT = new ArrayList<C>();

	// Returns the list of ProposalContent objects
	public List<C> getContentList() {
		return CONTENT;
	}
	
	// Adds new ProposalContent object to the list of ProposalContentList
	public boolean add(C content) {
		return CONTENT.add(content);
	}
	
	// Removes ProposalContent object from the list
	public boolean remove(C content) {
		return CONTENT.remove(content);
	}
	
	// Returns sum of ProposalContent objects costs without any additions
	// (the total sum with additions is returned by getTotalSum() method)
	public float getSum() {
		float sum = 0;
		if (CONTENT.size() == 0) {
			return 0;
		}
		for (C c : CONTENT) {
			sum += c.getTotal();
		}
		return sum;
	}
	
	// Set the no attribute correctly in the list
	public void reorder() {
		int i = 1;
		for (C c : CONTENT) {
			c.setNo(i++);
		}
	}

	// Returns the total sum of ProposalContent objects including additional costs
	// Dependent on implementation of an object.
	public abstract float getTotalSum();
	
	public abstract C getNewContent();
}
